package modellayer;
import java.util.ArrayList;

/**
 * Write a description of class PersonContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class KundeContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<Kunde> kundeListe;
    private static KundeContainer instance;

    /**
     * Constructor for objects of class PersonContainer
     */
    public KundeContainer()
    {
        kundeListe = new ArrayList<Kunde>();
        kundeListe.add(new Kunde("Peter", "Aalborg", "12345678", "på taget", 1));
        kundeListe.add(new Kunde("Jonas", "Danmark", "87654321", "på mars", 4));
        kundeListe.add(new Kunde("Dani", "Space", "11111111", "her", 3));
    }

    /**
     * Singleton for class KundeContainer
     */
    public static KundeContainer getInstance()
    {
        if(instance == null)
        {
            instance = new KundeContainer();
        }
        return instance;
    }

    /**
     * Adds a kunde to the arraylist kundeListe.
     * 
     * @param kunde a kunde object to be added to the list.
     */
    public void addKunde(Kunde kunde)
    {
        kundeListe.add(kunde);
    }

    /**
     * Finds a object Kunde with the given String stregkode using a while loop.
     * 
     * @param  telefon  A string that is used to search for a kunde with the given string.
     * @return     An object kunde that have the String telefon as an attribute, or null if no kunde is found.
     */
    public Kunde findKunde(String telefon)
    {
        Kunde kunde = null;
        int arraySize = kundeListe.size();
        boolean found = false;
        int i = 0;

        while(!kundeListe.isEmpty() && i < arraySize && found == false)
        {
            if(kundeListe.get(i).getTelefon().equals(telefon))
            {
                kunde = kundeListe.get(i);
                found = true;
            }
            i++;
        }

        return kunde;
    }
}
